<?php

namespace App\Models;

use App\Exceptions\CategoryNotFound;
use App\Models\Traits\Curl;
use App\Models\Traits\RoomInfo;
use Illuminate\Database\Eloquent\Model;

/**
 * @author kuddy
 * Class Platform
 * @package App\Models
 * @property string $api_url
 * @property string $name
 */
class Platform extends Model
{
    use Curl;
    use RoomInfo;

    protected $fillable = [
        'name',
        'api_url'
    ];

    protected $hidden = [
        'api_url',
        'created_at',
        'updated_at'
    ];

    protected function getRoomsAttribute(): array
    {
        try {
            $response = $this->curlGet($this->getUri());
            if (false !== $response) {
                $rooms = $this->getRoomList($response);
            }
        } catch (CategoryNotFound $exception) {
            logger()->warning($exception->getMessage());
        }
        return $rooms ?? [];
    }

    /**
     * @author kuddy
     * @return string
     * @throws CategoryNotFound
     */
    protected function getUri()
    {
        $category = $this->category;
        $uri = $this->api_url . $this->transCategory($category);
        return $uri;
    }

    protected function getPlatformName(): string
    {
        return $this->name;
    }
}
